import Vue from 'vue'
import Router from 'vue-router'
const _import = require('./_import_' + process.env.NODE_ENV)

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRouterMap = [
  { path: '/login', component: () => import('@/views/login/index'), hidden: true },
  { path: '/404', component: () => import('@/views/404'), hidden: true },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    name: 'Dashboard',
    hidden: true,
    children: [{
      path: 'dashboard',
      component: () => import('@/views/dashboard/index')
    }]
  },
  {
    path: '/example',
    component: Layout,
    redirect: '/example/table',
    name: 'Example',
    hidden: true,
    meta: { title: 'Example', icon: 'example' },
    children: [
      {
        path: 'table',
        name: 'Table',
        component: () => import('@/views/table/index'),
        meta: { title: 'Table', icon: 'table' }
      },
      {
        path: 'tree',
        name: 'Tree',
        component: () => import('@/views/tree/index'),
        meta: { title: 'Tree', icon: 'tree' }
      }
    ]
  },

  {
    path: '/form',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        name: 'Form',
        component: () => import('@/views/form/index'),
        meta: { title: 'Form', icon: 'form' }
      }
    ]
  },

  {
    path: '/icon',
    component: Layout,
    hidden: true,
    children: [{
      path: 'index',
      component: _import('svg-icons/index'),
      name: 'icons',
      meta: { title: 'icons', icon: 'icon', noCache: true }
    }]
  },

  { path: '*', redirect: '/404', hidden: true }
]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: '/server',
    component: Layout,
    redirect: '/server/servermain',
    name: 'Server',
    meta: { title: 'Server', icon: 'component', roles: ['manager','res_manager'] },
    children: [
      {
        path: 'servermain',
        name: 'ServerMain',
        component: () => import('@/views/server/servermain/index'),
        meta: { title: 'ServerMain', icon: 'table', roles: ['manager','res_manager'] }
      },
      {
        path: 'serverdetail',
        name: 'ServerDetail',
        component: () => import('@/views/server/serverdetail/index'),
        meta: { title: 'ServerDetail', icon: 'form', roles: ['manager','res_manager'] }
      }
    ]
  },

  {
    path: '/resources',
    component: Layout,
    redirect: '/resources/query',
    name: 'Resources',
    meta: { title: 'Resources', icon: 'table', roles: ['res_manager'] },
    children: [
      {
        path: 'queryresources',
        name: 'QueryResources',
        component: () => import('@/views/resources/query/index'),
        meta: { title: 'Query Resources', icon: 'table', roles: ['res_manager'] }
      },
      {
        path: 'addresources',
        name: 'AddResources',
        component: () => import('@/views/resources/add/index'),
        meta: { title: 'Add Resources', icon: 'table', roles: ['res_manager'] }
      },
      {
        path: 'resourceusage',
        name: 'ResDetailUsage',
        hidden: true,
        component: () => import('@/views/resources/detail/index'),
        meta: { title: 'Resource Usage', icon: 'table', roles: ['res_manager']}
      }
    ]
  },

  {
    path: '/application',
    component: Layout,
    redirect: '/application/query',
    name: 'Application',
    meta: { title: 'Application', icon: 'peoples'},
    children: [
      {
        path: 'queryapplication',
        name: 'QueryApplication',
        component: () => import('@/views/application/query/index'),
        meta: { title: 'Applications', icon: 'peoples', roles: ['manager','res_manager'] }
      },
      {
        path: 'myapplications',
        name: 'MyApplications',
        component: () => import('@/views/application/myapplications/index'),
        meta: { title: 'My Applications', icon: 'peoples' }
      },
      {
        path: 'mytodoitems',
        name: 'MyTodoItems',
        component: () => import('@/views/application/mytodoitems/index'),
        meta: { title: 'Todo Items', icon: 'peoples', roles: ['manager','res_manager'] }
      },
      {
        path: 'addapplication',
        name: 'AddApplication',
        hidden: true,
        component: () => import('@/views/application/add/index'),
        meta: { title: 'New Resource Application', icon: 'people'}
      },
      {
        path: 'tempqueryresources',
        name: 'TempResourcesList',
        component: () => import('@/views/application/resourceslist/index'),
        meta: { title: 'Resources List', icon: 'table'}
      }
    ]
  },

  {
    path: '/myapplication',
    component: Layout,
    redirect: '/myapplication/index',
    name: 'My Application',
    meta: { title: 'My Demand', icon: 'component' },
    children: [
      {
        path: 'index',
        name: 'My Application',
        component: () => import('@/views/myapplication/index'),
        meta: { title: 'My Demand', icon: 'table' }
      },
      {
        path: 'addapplication',
        name: 'Add Application',
        component: () => import('@/views/myapplication/addapplication/index'),
        meta: { title: 'Add Demand', icon: 'form' }
      }
    ]
  },

  {
    path: '/mytodolist',
    component: Layout,
    meta: { roles: ['manager'] },
    children: [
      {
        path: 'index',
        name: 'My to-do List',
        component: () => import('@/views/mytodolist/index'),
        meta: { title: 'My to-do List', icon: 'table' }
      }
    ]
  },

  {
    path: '/authorization',
    component: Layout,
    redirect: '/authorization/query',
    name: 'Authorization',
    meta: { title: 'Authorization', icon: 'peoples', roles: ['sys_manager'] },
    children: [
      {
        path: 'queryauth',
        name: 'QueryAuth',
        component: () => import('@/views/Authorization/query/index'),
        meta: { title: 'QueryAuth', icon: 'peoples', roles: ['sys_manager'] }
      },
      {
        path: 'editauth',
        name: 'EditAuth',
        component: () => import('@/views/Authorization/Edit/index'),
        meta: { title: 'EditAuth', icon: 'people', roles: ['sys_manager'] }
      }
    ]
  },

  {
    path: '/usersettings',
    component: Layout,
    children: [
      {
        path: 'index',
        name: 'User Settings',
        component: () => import('@/views/usersettings/index'),
        meta: { title: 'User Settings', icon: 'people' }
      }
    ]
  }
]

